<?php
namespace app\manager\model;

use think\Model;
use app\common\traits\model\TraitModel;

class Caravans extends Model
{
    use TraitModel;

    protected $type = [
    'piccaravan' => 'array',
    'caravancover' => 'array',
    ];

    protected $autoWriteTimestamp = 'timestamp';
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    protected $table = 'caravan';

    public function getZiduna()
    {
        $ziduan=array(
            'kitchen'=>['1'=>'有','2'=>'无'],
            'bathroom'=>['1'=>'有','2'=>'无'], 
            'wifi'=>['1'=>'有','2'=>'无'],
            'tv'=>['1'=>'有','2'=>'无'],
            'washer'=>['1'=>'有','2'=>'无'],
            'air_condition'=>['1'=>'有','2'=>'无'], 
            'the_shower'=>['1'=>'有','2'=>'无'],
            'extinguisher'=>['1'=>'有','2'=>'无'],
            'annunciator'=>['1'=>'有','2'=>'无'],
            'monitored'=>['1'=>'有','2'=>'无'],
             );
         return $ziduan;
         return $this->all();
    }

    public function getKitchenAttr($value)
    {
        $status = [2=>'无',1=>'有'];
        return $status[$value];
    }
    public function getBathroomAttr($value)
    {
        $status = [2=>'无',1=>'有'];
        return $status[$value];
    }
    

    /**
     * 对应营地信息
     * @return [type] [description]
     */
    public function camps()
    {
    	return $this->belongsTo('Camps','services');
    }

    public function users()
    {
        return $this->belongsTo('Users','user_id');
    }
    

    public function calendars()
    {
    	return $this->hasMany('Calendars','park_id');
    }

    public function getCalendar($park, $s, $e)
    {
    	return $park->calendars()->where('t','between time', [$s, $e])->select();
    }

    public function carcates(){
        return $this->belongsTo('CarCates','car_cates_id');
    }

    public function carrenders(){
        return $this->belongsTo('CarRenders','car_renders_id');
    }

    public function carbrands(){
        return $this->belongsTo('CarBrands','car_brands_id');
    }
    public function carcountries(){
        return $this->belongsTo('CarCountries','car_countries_id');
    }
    public function drivertypes(){
        return $this->belongsTo('DriverTypes','driver_type');
    }

    

    public function getCaravans(){
        return $this->getAllInfo();
    }

    public function getCaravansLists($querys = [])
    {
        $id = session('manager.id');
        $camp_id = model('CampManagers')->where('id',$id)->value('camp_id');//halt($camp_id);
        $querys = array_merge($querys,['services' => $camp_id]);
        return $this->getInfoList($querys);
    }

    public function getCaravanInfo($id)
    {
        return $this->where('id',$id)->find();
    }

    public function updateCaravan($id, $post_caravan_info)
    {
        return $this->update(array_merge($post_caravan_info, ['id' => $id]));
    }

    public function setChecked($id,$status)
    {
        $caravaninfo = $this->where('user_id',$id)->find();
        $caravaninfo->status = $status;
        return $caravaninfo->save();
    }

    public function createCaravan($post_caravan_info)
    {
        return $this->create($post_caravan_info);
    }

}